﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace AltimilliaLibrary.State
{
  public enum WalkDirection
  {
    WalkLeft, WalkRight, WalkDown, WalkUp
  }

  public class WalkLeft : IState
  {
    public static WalkLeft instan = new WalkLeft();

    public static WalkLeft GetInstance()
    {
      return instan;
    }

    public void UpdatePosition(Sprite gc)
    {
      float elapsedTime = (float)gc.gameTime.ElapsedGameTime.TotalSeconds;
      gc.absPosition = new Vector2(Math.Max(gc.absPosition.X - gc.maxSpeed * elapsedTime,
                       Utilities.TiletoPixel(gc.TilePosition.X - 1)), gc.absPosition.Y);
      gc.Scrolling = true;

    }

    public string GetState()
    {
      return "WalkLeft";
    }
  }
  public class WalkRight : IState
  {

    public static WalkRight instan = new WalkRight();

    public static WalkRight GetInstance()
    {
      return instan;
    }

    #region IState Members

    public void UpdatePosition(Sprite gc)
    {
      float elapsedTime = (float)gc.gameTime.ElapsedGameTime.TotalSeconds;
      gc.absPosition = new Vector2(Math.Min(gc.absPosition.X + gc.maxSpeed * elapsedTime,
                       Utilities.TiletoPixel(gc.TilePosition.X + 1)), gc.absPosition.Y);
      gc.Scrolling = true;
    }

    public string GetState()
    {
      return "WalkRight";
    }

    #endregion
  }
  public class WalkDown : IState
  {
    public static WalkDown instan = new WalkDown();

    public static WalkDown GetInstance()
    {
      return instan;
    }

    #region IState Members

    public void UpdatePosition(Sprite gc)
    {
      float elapsedTime = (float)gc.gameTime.ElapsedGameTime.TotalSeconds;
      gc.absPosition = new Vector2(gc.absPosition.X,Math.Min(gc.absPosition.Y + gc.maxSpeed * elapsedTime,Utilities.TiletoPixel(gc.TilePosition.Y + 1)));
      gc.Scrolling = true;
    }

    public string GetState()
    {
      return "WalkDown";
    }

    #endregion
  }
  public class WalkUp : IState
  {
    public static WalkUp instan = new WalkUp();

    public static WalkUp GetInstance()
    {
      return instan;
    }

    #region IState Members

    public void UpdatePosition(Sprite gc)
    {
      float elapsedTime = (float)gc.gameTime.ElapsedGameTime.TotalSeconds;
      gc.absPosition = new Vector2(gc.absPosition.X, Math.Max(gc.absPosition.Y - gc.maxSpeed * elapsedTime, Utilities.TiletoPixel(gc.TilePosition.Y - 1)));
      gc.Scrolling = true;
    }

    public string GetState()
    {
      return "WalkUp";
    }

    #endregion
  }
}
